//
//  ZYXFindPassViewController.m
//  RuiBeiKang
//
//  Created by 代码女神 on 2019/1/4.
//  Copyright © 2019年 JW. All rights reserved.
//

#import "ZYXFindPassViewController.h"
#import "TimeDownBtn.h"

@interface ZYXFindPassViewController ()

@property (weak, nonatomic) IBOutlet UITextField *phoneTextF;
@property (weak, nonatomic) IBOutlet UITextField *codeTextF;
@property (weak, nonatomic) IBOutlet TimeDownBtn *getCodeBtn;
@property (weak, nonatomic) IBOutlet UITextField *passTextF;
@property (weak, nonatomic) IBOutlet UITextField *surePassTextF;

@end

@implementation ZYXFindPassViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

- (void)setupViews{
    self.view.backgroundColor = [UIColor whiteColor];
    self.isHiddenNav = YES;
}

- (IBAction)getCodeAction:(TimeDownBtn *)sender {
     [self.view endEditing:YES];
    ///判断手机号的输入
    NSString *phone = self.phoneTextF.text;
    if (![Functions isPhoneNumber:phone]|| ![Functions validateMobile:phone]) {
        [JKToast showWithText:@"手机号码格式不正确"];
        return;
    }
    [NetWork POSTWithUrlString:kInterfaceAllUrl(PATH_userCheckCode) parmas:@{@"phone":phone} successBloock:^(NSDictionary *responseObject) {
        NSLog(@"%@",responseObject);
        if ([responseObject[@"code"] isEqualToNumber:@200]) {
            //获取验证码
            [sender startTimeDown];
            
        }else{
            [JKToast showWithText:responseObject[@"message"]];
        }
        
        
    } failureBlock:^(NSError *error) {
        
    }];
    
}
- (IBAction)finishAction:(id)sender {
    
     [self.view endEditing:YES];
    //完成
    NSString *phone = self.phoneTextF.text;
    NSString *code = self.codeTextF.text;
    NSString *pass = self.passTextF.text;
    NSString *surePass = self.surePassTextF.text;
    
    if (![Functions isPhoneNumber:phone]|| ![Functions validateMobile:phone]) {
        [JKToast showWithText:@"手机号码格式不正确"];
        return;
    }
    if (![Functions isPassward:pass] || ![Functions isPassward:surePass]) {
        [JKToast showWithText:@"密码格式不正确"];
        return;
    }
    if (![pass isEqualToString:surePass]){
        [JKToast showWithText:@"两次输入密码不一致"];
        return;
    }
    if (![Functions isVerfyCode:code]){
        [JKToast showWithText:@"验证码格式不正确"];
        return;
    }
    [NetWork POSTWithUrlString:kInterfaceAllUrl(PATH_userCheckcodeop) parmas:@{@"username":phone,@"password":pass,@"password2":surePass,@"code":code} successBloock:^(NSDictionary *responseObject) {
        NSLog(@"%@",responseObject);
        if ([responseObject[@"code"] isEqualToNumber:@200]) {
            
            UserModel *model = [UserModel shareUserModel];
            [model setupValuesForDictionary:responseObject[@"data"]];
         
            [self.navigationController popViewControllerAnimated:YES];
            
        }else{
            [JKToast showWithText:responseObject[@"message"]];
        }
        
        
    } failureBlock:^(NSError *error) {
        
    }];
}
- (IBAction)loginAction:(id)sender {
    //返回登录
    [self.navigationController popViewControllerAnimated:YES];
}


@end
